﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace Extend.Pool
{
    public class ComponentPool<T> : UnityObjPoolBase<T> where T : Component
    {
        /*
         Unity 组件 池
             */

        protected ComponentPool()
        {

        }

        public static ComponentPool<T> Create(T original, Transform parent = null, int capacity = int.MaxValue)
        {
            ComponentPool<T> pool = new ComponentPool<T>();
            pool.Init(original, parent, capacity);
            return pool;
        }

        protected override GameObject GetGameobject(T t)
        {
            return t.gameObject;
        }

        protected override T GetNewInstance()
        {
            var go = GameObject.Instantiate<T>(_original);
            go.transform.SetParent(_parent, false);
            return go;
            //return GameObject.Instantiate<T>(_original, _parent);
        }

        protected override Transform GetTransform(T t)
        {
            return t.transform;
        }
    }
}

